<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>
        云客客户关系管理系统
    </title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" href="/static/css/x-admin.css" media="all">
</head>

<div class="x-body">
    <form class="layui-form">
        <div class="layui-form-item">
            <label for="staffId" class="layui-form-label">
                <span class="x-red">*</span>员工编号
            </label>
            <div class="layui-input-inline">
                <input type="text" id="staffId" name="staffId" required="" lay-verify="required"
                       autocomplete="off" class="layui-input" readonly="readonly" value="${staff.id}">
            </div>
        </div>
        <div class="layui-form-item">
            <label for="role" class="layui-form-label">
                <span class="x-red">*</span>部门名称
            </label>
            <div class="layui-input-inline">
                <select name="deptId" id="deptId">
                    <#list deptList as dept>
                        <#if staff.deptId==dept.id>
                            <option value="${dept.id}" selected>${dept.name}</option>
                        <#else>
                            <option value="${dept.id}">${dept.name}</option>
                        </#if>
                    </#list>
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label for="staffName" class="layui-form-label">
                <span class="x-red">*</span>员工名称
            </label>
            <div class="layui-input-inline">
                <input type="text" id="staffName" name="staffName" required="" lay-verify="required"
                       autocomplete="off" class="layui-input" value="${staff.name}">
            </div>
        </div>
        <div class="layui-form-item">
            <label for="staffJob" class="layui-form-label">
                <span class="x-red">*</span>岗位名称
            </label>
            <div class="layui-input-inline">
                <input type="text" id="staffJob" name="staffJob" required="" lay-verify="required"
                       autocomplete="off" class="layui-input" value="${staff.job}">
            </div>
        </div>
        <div class="layui-form-item layui-form-text">
            <label for="duty" class="layui-form-label">岗位职责</label>
            <div class="layui-input-block">
                <textarea placeholder="请输入内容" class="layui-textarea" id="duty">${staff.duty}</textarea>
            </div>
        </div>
        <div class="layui-form-item" pane>
            <label class="layui-form-label">员工性别</label>
            <div class="layui-input-block">
            <#if "男"==staff.sex>
                <input type="radio" name="sex" checked value="男" title="男"/>
                <input type="radio" name="sex" value="女" title="女"/>
            </#if>
            <#if "女"==staff.sex>
                <input type="radio" name="sex" value="男" title="男"/>
                <input type="radio" name="sex" checked value="女" title="女"/>
            </#if>
            </div>
        </div>
        <div class="layui-form-item">
            <label for="pho" class="layui-form-label">
                <span class="x-red">*</span>工作电话
            </label>
            <div class="layui-input-inline">
                <input type="text" id="pho" name="pho" required="" lay-verify="required"
                       autocomplete="off" class="layui-input" value="${staff.pho}">
            </div>
        </div>
        <div class="layui-form-item">
            <label for="tel" class="layui-form-label">
                <span class="x-red">*</span>手机号码
            </label>
            <div class="layui-input-inline">
                <input type="tel" id="tel" name="tel" lay-verify="phone" autocomplete="off" class="layui-input" value="${staff.tel}">
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">员工邮箱</label>
                <div class="layui-input-inline">
                    <input type="text" name="email" lay-verify="email" autocomplete="off" class="layui-input" value="${staff.email}">
                </div>
            </div>
        </div>
        <div class="layui-form-item">
            <label for="role" class="layui-form-label">
                <span class="x-red">*</span>职务名称
            </label>
            <div class="layui-input-inline">
                <select name="jobId" id="jobId">
                    <#list jobList as job>
                        <#if staff.jobId==job.id>
                            <option value="${job.id}" selected>${job.name}</option>
                        <#else>
                            <option value="${job.id}">${job.name}</option>
                        </#if>
                    </#list>
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">员工状态</label>
            <div class="layui-input-block">
                <select name="interest" lay-filter="staffState" id="staffState">
                    <#if "正常"==staff.state>
                        <option value="正常" selected>正常</option>
                        <option value="异常">异常</option>
                    </#if>
                    <#if "异常"==staff.state>
                        <option value="正常">正常</option>
                        <option value="异常" selected>异常</option>
                    </#if>
                </select>
            </div>
        </div>
        <div class="layui-form-item" pane>
            <label class="layui-form-label">离职状态</label>
            <div class="layui-input-block">
                <#if "是"==staff.leaveOffice>
                    <input type="radio" name="leaveState" checked value="是" title="是"/>
                    <input type="radio" name="leaveState" value="否" title="否"/>
                </#if>
                <#if "否"==staff.leaveOffice>
                    <input type="radio" name="leaveState" value="是" title="是"/>
                    <input type="radio" name="leaveState" checked value="否" title="否"/>
                </#if>
            </div>
        </div>
        <div class="layui-form-item layui-form-text">
            <label for="remark" class="layui-form-label">备注</label>
            <div class="layui-input-block">
                <textarea placeholder="请输入内容" class="layui-textarea" id="remark">${staff.remark}</textarea>
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label" for="hireDate">入职日期</label>
            <div class="layui-input-inline">
                <input type="date" name="date" value="${staff.hireDate?string("yyyy-MM-dd hh:mm:ss")}" id="hireDate" lay-verify="date" placeholder="yyyy-mm-dd" autocomplete="off" class="layui-input" onclick="layui.laydate({elem: this})">
            </div>
        </div>
        <div class="layui-form-item">
            <label for="L_sign" class="layui-form-label">
            </label>
            <button class="layui-btn" key="set-mine" lay-filter="save" lay-submit>
                保存
            </button>
        </div>
    </form>
</div>
</body>
<script src="/static/lib/layui/layui.js" charset="utf-8">
</script>
<script src="/static/js/x-layui.js" charset="utf-8">
</script>
<script>
    layui.use(['form','layer'], function() {
        $ = layui.jquery;
        var form = layui.form()
                , layer = layui.layer;

        //自定义验证规则
        form.verify({
            nikename: function (value) {
                if (value.length < 5) {
                    return '昵称至少得5个字符啊';
                }
            }
            , pass: [/(.+){6,12}$/, '密码必须6到12位']
            , repass: function (value) {
                if ($('#L_pass').val() != $('#L_repass').val()) {
                    return '两次密码不一致';
                }
            }
        });
        var app=0;
        form.on('submit(save)', function () {
            $.ajax({
                type: "POST",
                dataType: "json",
                url: "/staff/editStaff",
                data: {
                    staffId:$("#staffId").val(),
                    deptId: $("#deptId").val(),
                    staffName: $("#staffName").val(),
                    staffJob: $("#staffJob").val(),
                    duty: $("#duty").val(),
                    sex: $('input[name="sex"]:checked').val(),
                    pho:$("#pho").val(),
                    tel:$("#tel").val(),
                    email:$("#email").val(),
                    jobId:$("#jobId").val(),
                    state:$("#staffState").val(),
                    leaveState: $('input[name="leaveState"]:checked').val(),
                    remark:$("#remark").val(),
                    hireDate: $("#hireDate").val()
                },
                success: function (msg) {
                    app=msg.data;
                    alert(app);
                }
            });

            if(app<0){
                layer.alert("编辑失败", {icon: 6}, function () {
                    // 获得frame索引
                    var index = parent.layer.getFrameIndex(window.name);
                    //关闭当前frame
                    parent.layer.close(index);
                });
            }else{
                layer.alert("编辑成功", {icon: 6}, function () {
                    // 获得frame索引
                    var index = parent.layer.getFrameIndex(window.name);
                    //关闭当前frame
                    parent.layer.close(index);
                });
            }
            return false;

        })
    })
</script>
</html>